Function.prototype.myCall = function (context) {
  // context是接受的第一个参数，指定的this对象
  if (typeof this !== 'function') {
    throw new Error('不是函数')
  }
  const obj = context || window
  obj.fn = this
  const args = [...arguments].slice(1)
  const res = obj.fn(...args)
  delete obj.fn
  return res
}

//用法：f.call(obj,arg1)
let name = '55555'
function f(a, b) {
  console.log(a + b)
  console.log(this.name)
}
let obj = {
  name: 'wp'
}
f.myCall(obj, 1, 2) //否则this指向window
